﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Enferno.Public.Web.Models;
using Enferno.StormApiClient.Shopping;

namespace Enferno.Public.Web.Mappers.Resolvers
{
    public class PromotionsResolver<TBasketModel, TBasketItemModel, TPromotionModel, TOnHandStatusModel, TPriceModel, TProductFileModel> : ValueResolver<TBasketModel, PromotionList>
        where TBasketModel : BasketBaseModel<TBasketItemModel, TPromotionModel, TOnHandStatusModel, TPriceModel, TProductFileModel>
        where TBasketItemModel : BasketItemBaseModel<TPriceModel>
        where TPromotionModel : PromotionBaseModel<TProductFileModel>
        where TOnHandStatusModel : OnHandStatusModel
        where TPriceModel : PriceModel
        where TProductFileModel : ProductFileModel
    {
        protected override PromotionList ResolveCore(TBasketModel source)
        {
            var promotionList = new PromotionList();
            promotionList.AddRange(source.Promotions.Select(Mapper.Map<TPromotionModel, Promotion>));

            return promotionList;
        }
    }

    public class PromotionModelsResolver<TPromotionModel, TProductFileModel> : ValueResolver<Basket, IEnumerable<TPromotionModel>>
        where TPromotionModel : PromotionBaseModel<TProductFileModel>
        where TProductFileModel: ProductFileModel
    {
        protected override IEnumerable<TPromotionModel> ResolveCore(Basket source)
        {
            var promotionModelList = source.AppliedPromotions.Select(Mapper.Map<Promotion, TPromotionModel>).ToList();
            return promotionModelList;
        }
    }
}
